﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="mtaev_seisundid_vastus", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(MtaevSeisundidVastus))]
    public class MtaevSeisundidVastusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IMtaevSeisundidVastus clazz;
        
        public MtaevSeisundidVastusSerializer(IMtaevSeisundidVastus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("seisundid");
            if (clazz.Seisundid!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("mtaev_seisundid_seisund", "http://producers.arireg.xtee.riik.ee/producer/arireg", clazz.Seisundid.Count);
                for (int x = 0; ((clazz.Seisundid != null) 
                            && (x < clazz.Seisundid.Count)); x = (x + 1)) {
                    if (clazz.Seisundid[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaSeisundid = this.GetMetaData(clazz.Seisundid[x]);
                        Writer.WriteTypeAttribute(metaSeisundid.TypeQualifiedName.Namespace, metaSeisundid.TypeQualifiedName.Name);
                        metaSeisundid.NewSerializer(clazz.Seisundid[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Seisundid");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="seisundid") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtaev_seisundid_vastus>seisundid");
                }
                clazz.Seisundid = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMtaevSeisundidSeisund>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("seisundid");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtaev_seisundid_seisundid>item");
                        }
                        global::Xtee.Core.SerializationMetadata metaSeisundid = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMtaevSeisundidSeisund>(Reader, "mtaev_seisundid_seisund", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                        global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMtaevSeisundidSeisund item = metaSeisundid.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMtaevSeisundidSeisund>();
                        clazz.Seisundid.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("item");
                            metaSeisundid.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtaev_seisundid_vastus>seisundid", Reader.LocalName);
            }
        }
    }
}
